import { useState, useCallback } from 'react';
import { message } from 'antd';

export interface Group {
  id: string;
  name: string;
  description?: string;
  memberCount?: number;
  createTime?: string;
}

export const useGroups = () => {
  const [loading, setLoading] = useState(false);
  const [groups, setGroups] = useState<Group[]>([
    {
      id: 'group-001',
      name: '开发组',
      description: '负责系统开发和维护',
      memberCount: 12,
      createTime: '2024-01-15',
    },
    {
      id: 'group-002',
      name: '测试组',
      description: '负责系统测试和质量保证',
      memberCount: 8,
      createTime: '2024-01-20',
    },
    {
      id: 'group-003',
      name: '运维组',
      description: '负责系统运维和部署',
      memberCount: 5,
      createTime: '2024-01-25',
    },
  ]);

  const fetchGroups = useCallback(async () => {
    try {
      setLoading(true);
      // 模拟API调用
      await new Promise(resolve => setTimeout(resolve, 500));
      message.success('用户组列表加载成功');
    } catch (error) {
      message.error('加载用户组失败');
    } finally {
      setLoading(false);
    }
  }, []);

  return {
    groups,
    loading,
    fetchGroups,
  };
}; 